package org.duoyi.striver.model.impl;

import cn.hutool.core.util.RandomUtil;
import lombok.Getter;
import org.duoyi.striver.model.Point;

/**
 * 区域
 *
 * @author chenyuheng create class on 2021-05-08
 */
@Getter
public class Region {

    private final int x1;
    private final int y1;
    private final int x2;
    private final int y2;

    private Region(int x1, int y1, int x2, int y2) {
        this.x1 = x1;
        this.y1 = y1;
        this.x2 = x2;
        this.y2 = y2;
    }

    public static Region in(int x1, int y1, int x2, int y2) {
        return new Region(x1, y1, x2, y2);
    }

    public Point randomPoint() {
        int x = RandomUtil.randomInt(x1, x2);
        int y = RandomUtil.randomInt(y1, y2);
        return PointImpl.on(x, y);
    }

    public boolean randomLeftClick() {
        return randomPoint().leftClick();
    }

}
